
namespace <?=$app.'\\'.$module.'\\event'?>;

use <?=$modelNameSpace?> as <?=basename($modelNameSpace)?>Model;
use app\common\utils\JsonService;

class <?=$event_name?>{

    /*
    * <?=str_replace('表','',$table_info['Comment'])?>列表
    */
    public static function <?=lcfirst($tpName)?>List($params){
        //$params = array_filter(request()->param());
        $page = ! empty($params['page']) && $params['page'] >= 1 ? $params['page'] : 1;
        $where = [];
<?php
if(!empty($config['search'])){
    foreach($config['search'] as $k=>$v){ ?>
        if($<?=$v['field']?> = isset($params['<?=$v['field']?>'])){
    <?php if($v['field'] == $config['pri_key']){?>
                $where[] = ['<?=$config['pri_key']?>','=',$params['<?=$v['field']?>']];
    <?php }else{ ?>
                $where[] = ['<?=$v['field']?>','like',"%{$params['<?=$v['field']?>']}%"];
    <?php } ?>
        }
    <?php
        }
    }
?>
         $condition = [
            'where' => $where,
            'order' => ['<?=$config['pri_key']?>' => 'desc'],
                'paginate' => [
                'page' => $page,
                'query' => $params,
                'list_rows'=>20,
            ],
        ];
        $<?=lcfirst($tpName)?> = <?=basename($modelNameSpace)?>Model::getPageAll($condition);
        return $<?=lcfirst($tpName)?>;
    }


    /*
    * 新增<?=str_replace('表','',$table_info['Comment'])?>

    */
    public static function create<?=($tpName)?>($data){

        try {
            <?=basename($modelNameSpace)?>Model::create($data);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }

    /*
    * 更新<?=str_replace('表','',$table_info['Comment'])?>

    */
    public static function update<?=($tpName)?>($data){

        try {
            <?=basename($modelNameSpace)?>Model::updateOne($data, ['<?=$config['pri_key']?>' => $data['<?=$config['pri_key']?>']]);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }


}

